<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>评教系统数据统计</title>
    <!-- https://www.unmcc.com/unmcc/miva/JSPF/static/php/index.php -->
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
</head>
<body style="height: 100%; margin: 0 30px">
    <div id="container" style="height: 100%"></div>
    
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <script>
        var dom = document.getElementById("container");
        var myChart = echarts.init(dom);
        var app = {};

        var data = {
            legendData:[],
            seriesData: [],
        };

        var option = {
            xAxis: {
                max: 'dataMax',
            },
            yAxis: {
                type: 'category',
                data: data.legendData,
                inverse: true,
                animationDuration: 300,
                animationDurationUpdate: 300,
                max: 0,
            },
            series: [{
                realtimeSort: true,
                name: '评教系统数据统计',
                type: 'bar',
                data: data.seriesData,
                label: {
                    show: true,
                    position: 'right',
                    valueAnimation: true
                }
            }],
            legend: {
                show: true
            },
            animationDuration: 0,
            animationDurationUpdate: 3000,
            animationEasing: 'linear',
            animationEasingUpdate: 'linear'
        };
 
        axios.get('https://www.unmcc.com/unmcc/miva/JSPF/static/php/index.php').then(res=> {
            const mapping = {};
            res.data.list.forEach(val=> {
                const teacher = val.teacher;
                const score = Number(val.score);
                if (data.legendData.includes(teacher)===false){
                    data.legendData.push(teacher);
                    const teacher_data = {
                        name: teacher,
                        value: score,
                    };
                    data.seriesData.push(teacher_data);
                    mapping[teacher] = teacher_data;
                }else{
                    mapping[teacher].value += score;
                }
            });

            if (option && typeof option === 'object') {
                option.yAxis.max = data.legendData.length-1;
                myChart.setOption(option);
            }
        });
    </script>
</body>
</html>